import { getModules } from '@/api/login'

const user = {
  state: {
    menuitems: [],
    actions: []
  },

  mutations: {
    SET_MENUITEMS: (state, data) => {
      state.menuitems = JSON.stringify(data)
    },
    SET_ACTIONS: (state, data) => {
      state.actions = data
    }
  },

  actions: {
    // 获取权限
    GET_MODULES({ commit }) {
      return new Promise((resolve, reject) => {
        getModules().then(response => {
          commit('SET_MENUITEMS', response.data.menuitems)
          commit('SET_ACTIONS', response.data.actions)
          resolve(response.data.menuitems)
        }).catch(error => {
          reject(error)
        })
      })
    }
  }
}

export default user
